<?php
require_once 'Zend/Db/Table/Abstract.php';
class Model_DistrictMapper extends Zend_Db_Table_Abstract
{
	protected $_name = 'district';
	protected $_primary = 'DisID';
	
	//protected $_sequence = true; 
	
	public function getAllDistricts()
	{
		$rowset=$this->fetchAll();
		$rowCount = count($rowset);
		$result=Array();
		$i=0;
		if ($rowCount>0)
		{
			foreach ($rowset as $row) {
				$i=$i+1;
				$name = $row->Name;
				$id = $row->DisID;
				$dis=new Model_District();
				$dis->setId($id)->setName($name);
				$result[$i]=$dis;
			}		
		}
		return $result;
	}
	
	public function getTopDistricts()
	{
		$rowset=$this->fetchAll();
		$rowCount = count($rowset);
		$result=Array();
		$i=0;
		if ($rowCount>0)
		{
			foreach ($rowset as $row) {
				$i=$i+1;
				$name = $row->Name;
				$id = $row->DisID;
				$dis=new Model_District();
				$dis->setId($id)->setName($name);
				$result[$i]=$dis;
				if ($i>5) return $result;
			}
		}
		return $result;
	}
	
	public function getDistrict($disId)
	{
		$row=$this->fetchRow($this->select()->where('DisID=?',$disId));
		$result=new Model_District();
		if ($row)
		{
			$name = $row->Name;
			$id = $row->DisID;
			$result->setId($id)->setName($name);
		}
		return $result;
	}
		
	
}